
import mirny, os
from mirny.plugins.input import Input

class AllFiles(Input):
	name = _('All Files')
	description = _('Sample plugin to get data from each file on a filesystem')
	params = {	'filesystem': (_('Path of the filesystem'), str, True), }
	config = {	'filesystem': '/', }
	# example : filesystem=/mnt/data, /home/user/data, ...
	
	def init_plugin(self):
		self.fs = os.walk(self.config['filesystem'])
		self.files = []
	
	def next(self):
		try:
			try:
				self.file = self.files.pop()
				return True # ready for the next bunch
			except IndexError:
				self.dir, self.dirs, self.files = self.fs.next()
				self.next()
		except StopIteration:
			return False # we're done
	
	def get_source(self):
		return open(self.file, mode='rb')
	
	

